package com.beagle.njddapp.ui.activity.owner;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.beagle.njddapp.R;
import com.beagle.njddapp.bean.owner.NjBean;
import com.beagle.njddapp.utils.LocalDisplay;
import com.beagle.njddapp.utils.StatusBarUtil;
import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author hxx
 * @date 2021-03-22 21:46
 */
public class NjDetailActivity extends AppCompatActivity {

    @BindView(R.id.commom_title_tv)
    TextView tvTitle;
    @BindView(R.id.common_container)
    RelativeLayout container;
    @BindView(R.id.common_tv_right)
    TextView tvRight;
    @BindView(R.id.ed_device_number)
    TextView edNumber;
    @BindView(R.id.ed_device_creator)
    TextView edChangjia;
    @BindView(R.id.ed_device_addressr)
    TextView eddizhi;
    @BindView(R.id.tv_pinpai)
    TextView tvPinPai;
    @BindView(R.id.tv_type)
    TextView tvLeiXing;
    @BindView(R.id.tv_xinghao)
    TextView tvxinghao;
    @BindView(R.id.ed_device_bianhao)
    TextView edBianhao;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.ed_device_gauche)
    TextView edGuache;
    @BindView(R.id.ed_device_jxs)
    TextView edJxs;
    @BindView(R.id.ed_device_jsx_place)
    TextView edJxsPlace;
    @BindView(R.id.ed_device_youliang)
    TextView edYouLiang;
    @BindView(R.id.ed_device_zd_number)
    TextView edZd;
    @BindView(R.id.ed_device_size)
    TextView edSize;
    @BindView(R.id.ed_device_zhiliang)
    TextView edzhiliang;
    @BindView(R.id.ed_device_gonglv)
    TextView edGonglv;
    @BindView(R.id.ll_device_iv)
    LinearLayout lliv1;
    @BindView(R.id.iv1)
    ImageView ivFront;
    @BindView(R.id.iv2)
    ImageView ivback;
    @BindView(R.id.ed_device_bangding)
    TextView tvBd;
    @BindView(R.id.ed_device_xingshizheng)
    TextView edCardNumber;
    private NjBean njBean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nj_detail);
        ButterKnife.bind(this);
        StatusBarUtil.immersive(this);
        StatusBarUtil.darkMode(this);
        StatusBarUtil.setPaddingSmart(this,container);
        tvTitle.setText("农机设备详情");
        container.setBackgroundColor(Color.WHITE);
        tvRight.setText("修改");
        njBean= (NjBean) getIntent().getSerializableExtra("data");
        edNumber.setText(njBean.getMeshNum());
        edChangjia.setText(njBean.getMfrs());
        edJxs.setText(njBean.getAgentName());
        eddizhi.setText(njBean.getMfrsAddress());
        tvPinPai.setText(njBean.getBrandName());
        tvLeiXing.setText(njBean.getTypeName());
        tvxinghao.setText(njBean.getSizeName());
        edBianhao.setText(njBean.getSerialNo());
        edJxsPlace.setText(njBean.getAgentArea());
        edYouLiang.setText(njBean.getTankCapacity()+"");
        edZd.setText(njBean.getLotId());
        edGuache.setText(njBean.getTrailerNum());
        edSize.setText(njBean.getDimensions());
        edzhiliang.setText(njBean.getMass());
        edGonglv.setText(njBean.getPower());
        tvTime.setText(njBean.getProductionDate());
        tvBd.setText(njBean.getMeshUserName());
        edCardNumber.setText(njBean.getLicenseNum());
        Glide.with(this).load(njBean.getFrontLicenseUrl()).into(ivFront);
        Glide.with(this).load(njBean.getBackLicenseUrl()).into(ivback);
        addIMg(njBean.getFrontPictureUrl(),0);
        addIMg(njBean.getSidePictureUrl(),1);
        addIMg(njBean.getBackPictureUrl(),2);

    }

    public void addIMg(String url,int i){
        if (TextUtils.isEmpty(url)){
            return;
        }
        View view= LayoutInflater.from(this).inflate(R.layout.view_nj_iv,null);
        ImageView iv=view.findViewById(R.id.iv);
        TextView tv=view.findViewById(R.id.tv);

        Glide.with(this).load(url).into(iv);
        if (i==0){
            tv.setText("农机正面");
        }else if (i==1){
            tv.setText("农机侧面");
        }else {
            tv.setText("农机背面");
        }
        lliv1.addView(view);
    }




    @OnClick({R.id.common_back_iv,R.id.common_tv_right})
    public void onCLick(View view){
        switch (view.getId()){
            case R.id.common_back_iv:
                onBackPressed();
                break;
            case R.id.common_tv_right:
                startActivity(new Intent(this, DeviceUpdateActivity.class).putExtra("data",njBean));
                finish();
                break;
        }
    }
}
